import { defineConfig } from 'vite'
import vueJsx from '@vitejs/plugin-vue-jsx'
import vue from '@vitejs/plugin-vue'
import * as path from 'path'
import { resolve } from 'path'

// 实现 组件的按需加载
// 当引入 "unplugin-vue-components/vite 组件之后，页面中需要引入组件的地方就都不需要引入了
//import Components from "unplugin-vue-components/vite";
//import {
//    ViewUIResolver
//} from "unplugin-vue-components/resolvers";

// // 实现 Vue及Vue相关的库、api的 按需加载
import AutoImport from "unplugin-auto-import/vite";



// https://vitejs.dev/config/
export default defineConfig({
    base: '/competition-front/',
    plugins: [vue({
        reactivityTransform: true, //ref配置为$ref
    }),
    vueJsx({
        // include: ["**/*.vue"]
        // options are passed on to @vue/babel-plugin-jsx
    }),
    // ant自动引入组件配置后会引起ant主题定制出错
    //Components({
    //    resolvers: [
    //        ViewUIResolver()
    //    ]
    //}),
    AutoImport({
        // include: [
        // 	// /\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
        // 	/\.vue$/, /\.vue\?vue/, // .vue
        // ],
        imports: ["vue", "vue-router", "pinia"],
    })
    ],
    resolve: {
        //设置别名
        alias: [
            {
                find: "@",
                replacement: path.resolve(__dirname, "src"),
            },
            {
                find: "common",
                replacement: path.resolve(__dirname, "src/common"),
            },
            {
                find: "components",
                replacement: path.resolve(__dirname, "src/components"),
            },
        ]
    },
    css: {
        preprocessorOptions: {
            less: {
                modifyVars: {
                    // 用于全局导入，以避免需要单独导入每个样式文件。
                    // reference:  避免重复引用
                    hack: `true; @import (reference) "${resolve("src/style/variable.less")}"; `,
                },
                // 使用javascript能力定制主题
                // 设置为true后可以定制化主题，在main.js中引入'ant-design-vue/dist/antd.less'文件进行编译  
                // 这个项目UI库可能用到 iview 而不是 ant
                javascriptEnabled: true,
            }
        }
    },
    // 打包配置
    build: {
        minify: 'terser',
        terserOptions: {
            compress: {
                //生产环境时移除console
                drop_console: true,
                drop_debugger: true,
            },
        },
    },
    server: {
        host: '0.0.0.0',
        port: 2200
        // proxy: 'http://192.168.3.221:80'
        // proxy: 'https://g.aomao.com/latex'
    }
})
